<?php
/**
 * Created by PhpStorm.
 * User: soulmates
 * Date: 2017/8/15
 * Time: 上午8:12
 */
namespace app\restaurantadmin\controller;
use think\Controller;
class Order extends Controller
{
    public function order()
    {


        $sadmin=session('id');//获取店铺管理员id
        $shop= \think\Db::name('dining')->where('admin_id',$sadmin)->find();
        $shopid=$shop['shop_id'];//获取店铺id
        // var_dump($shopid);die;

        $sql = "select GROUP_CONCAT(oc.id ORDER BY oc.id DESC) AS orderList,o.order_id,o.uid,u.username,u.address,u.mobilenum,o.ordertime,o.isorder,o.state,o.comment from cr_users as u join cr_room as o on u.id=o.uid inner join cr_order as oc on o.order_id=oc.order_id where o.shop_id=".$shopid." group by o.order_id order by o.order_id desc";


        $orderData =\think\Db::name('room')->query($sql);
        $number=count($orderData);
        // dump($orderData);die();
        for($i = 0; $i < $number; $i ++) {
            $orderData[$i] ['num'] = $i; // 计数

            $order_id=$orderData[$i]['orderList'];

            $sql_list = "select * from cr_order where id in($order_id)";

            $orderlist = \think\Db::name('order')->query($sql_list);

        }
        //




        // dump($orderlist);die();
        $this->assign("orderData",$orderData);
        $this->assign("orderlist",$orderlist);



        return $this->fetch();
    }
}


//  // dump($orderData);die();
//         for($i=0;$i<sizeof($orderData);$i++){
//             // echo $orderData[$i]['orderList'];


//             foreach ($orderData as $value){
//               $value2[]= $value['orderList'];
//               $sql_list = "select * from cr_order where id in(".$value2[$i].")";
//               $orderlist[] = \think\Db::name('order')->query($sql_list);

//             }
//           // dump($value2);die();

//         }
// // dump($orderlist);die();
?>

